package com.demo3;

import java.util.Scanner;

/**
 * 长方形
 * 
 * @author J.L.Zhou jlzhou.top 版权所有
 */
public class Trilateral extends AbstractShape {

	/**
	 * 边一
	 */
	private float border1;
	/**
	 * 边二
	 */
	private float border2;
	/**
	 * 边三
	 */
	private float border3;

	public Trilateral(){
		super("三角形");
	}


	@Override
	public void inputBaseInfo(Scanner sc) {
		System.out.println("输入" + getName() + "的三边: ");
		border1 = sc.nextFloat();
		border2 = sc.nextFloat();
		border3 = sc.nextFloat();
		boolean flag = border1 + border2 > border3 && border1 + border3 > border2 && border2 + border3 > border1;
		if(!flag){
			System.out.println("您输入的三边不能构成"+getName());
			inputBaseInfo(sc);//递归调用
		}
	}

	@Override
	public float calcArea() {
		float s = perimeter / 2;
		return (float) Math.sqrt(s * (s - border1) * (s - border2) * (s - border3));
	}

	@Override
	public float caclPerimeter() {
		return border1 + border2 + border3;
	}

	@Override
	public String getBaseInfo() {
		return String.format("三边：%.2f,%.2f,%.2f",border1, border2,
				border3);
	}

	public float getBorder1() {
		return border1;
	}

	public void setBorder1(float border1) {
		this.border1 = border1;
	}

	public float getBorder2() {
		return border2;
	}

	public void setBorder2(float border2) {
		this.border2 = border2;
	}

	public float getBorder3() {
		return border3;
	}

	public void setBorder3(float border3) {
		this.border3 = border3;
	}

	public static void main(String[] args) {
		Trilateral rectangle = new Trilateral();
		rectangle.input(new Scanner(System.in));
		rectangle.show();
	}

}
